package cn.passlink.bletoothchat.Tools.FriendsFilter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import cn.passlink.bletoothchat.Entity.Friends;
import cn.passlink.bletoothchat.SqlTables.MyDatabaseHelper;

@SuppressLint("NotConstructor")
public class FriendsIsInTable {
    private SQLiteDatabase database;
    private  MyDatabaseHelper databaseHelper;

    public boolean FriendsIsInTable(Friends mFriend, String table, Context context) {
        databaseHelper = new MyDatabaseHelper(context, 2);
        database = databaseHelper.getReadableDatabase();

        String selection = "phone=?";
        String[] selectionArgs = {mFriend.getPhone()};
        Cursor cursor = null;
        try {
            // 查询表格并返回结果集游标
            cursor = database.query(table, null, selection, selectionArgs, null, null, null);

            // 如果结果集游标不为空且有数据，则说明数据存在于表格中
            if (cursor != null && cursor.getCount() > 0) {
                return true;
            }
        } finally {
            // 关闭游标和数据库连接
            if (cursor != null) {
                cursor.close();
            }
        }

        return false;
    }



}
